package com.kantboot.api.phone.repository;

import com.kantboot.api.phone.domain.dto.ApiPhoneSmsSearchDTO;
import com.kantboot.api.phone.domain.entity.ApiPhoneSms;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ApiPhoneSmsRepository extends JpaRepository<ApiPhoneSms,Long> {

    @Query("""
    FROM ApiPhoneSms AS p
    WHERE 
    (:#{#param.typeCode} IS NULL OR p.typeCode = '' OR p.typeCode = :#{#param.typeCode})
    AND (:#{#param.to} IS NULL OR p.to = '' OR p.to = :#{#param.to})
    AND (:#{#param.content} IS NULL OR p.content = '' OR p.content = :#{#param.content})
    AND (:#{#param.statusCode} IS NULL OR p.statusCode = '' OR p.statusCode = :#{#param.statusCode})
    ORDER BY p.id DESC
    """)
    Page<ApiPhoneSms> getBodyData(
            @Param("param")ApiPhoneSmsSearchDTO param,
            Pageable pageable);
}
